<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\AdminController;
use App\Models\AdminLog;
use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\Lang;

class AdminLogController extends AdminController
{
    /**
     * 日志管理
     * @return $this
     */
    public function getIndex()
    {
        //获取日志
        $log = new AdminLog();
        $log = $log->setHidden(['origin', 'ending', 'updated_at'])->orderBy('id', 'desc')->paginate(20);
        return view('admin.admin-log')->with(['log' => $log]);
    }

    /**
     * 查看日志
     * @param $id
     * @return string
     */
    public function getShow($id)
    {
        $log = AdminLog::find($id);
        $resultData = ['code' => 1];
        if($log)
        {
            //整理数据
            $log = $log->toArray();
            $log['title']       = $log['type'].'-'.(Lang::has('event.'.$log['event']) ? Lang::get('event.'.$log['event']) : $log['event']);
            $log['username']    = getUserName($log['uid']);
            $log['origin']      = $log['origin'] ? jsonFormat(json_decode($log['origin'])) : $log['origin'];
            $log['ending']      = $log['ending'] ? jsonFormat(json_decode($log['ending'])) : $log['ending'];
            $resultData = [
                'code'      =>      0,
                'data'      =>      $log
            ];
        }
        return json_encode($resultData);
    }
}
